import { configureStore } from '@reduxjs/toolkit'
import undoable, { excludeAction, StateWithHistory } from 'redux-undo'
import userReducer, { UserStateType } from './userReducer'
import componetnsReducer, { ComponentStateType } from './componetnsReducer'
import pageInfoReducer, { pageInfoType } from './pageInfoReducer'
export type StateType = {
  user: UserStateType
  // components: ComponentStateType
  components: StateWithHistory<ComponentStateType> //增加了undo
  pageInfo: pageInfoType
}
export default configureStore({
  reducer: {
    //分模块
    user: userReducer,
    // 没有 undo
    // components:componetnsReducer,
    // 加入undo 使用 redux-undo 可以很方便地为 Redux 应用程序添加撤销/重做功能。当 Redux store 中的状态发生变化时，redux-undo 会自动保存一个历史记录，然后可以通过分发不同的 action 类型来执行撤销和重做操作。
    components: undoable(componetnsReducer, {
      limit: 20,
      filter: excludeAction([
        'components/resetComponents',
        'components/changeSleectedId',
        'components/selectedPrevCompoent',
        'components/selectedNextCompoent',
      ]), //隔离不需要撤销的action
    }),
    pageInfo: pageInfoReducer,
  },
})
